class AnimatedObject{
    constructor(){
        super();
        this.backgroundColor = "#FFFFFF";
        this.foregroundColor = "#000000";
        this.highlighted = false;
        this.objectID = -1; //objectID：表示此对象ID的非负整数。必须不同于当前活动的任何ID。应尽可能小，以获得更好的性能。
        this.layer = 0;
        this.addedToScene = true;
        this.label = "";
        this.labelColor = "#000000";
        this.alpha = 1.0;
        this.x = 0;
        this.y = 0;
        this.minHeightDiff = 3;
        this.range = 5;
        this.highlightIndex = -1;
        this.highlightIndexDirty = true;
    }

    setBackgroundColor(newColor){
        this.backgroundColor = newColor;
    }

    setForegroundColor(newColor){
        this.foregroundColor = newColor;
    }

    setNull(){

    }

    getNull(){
        return false;
    }

    setAlpha(newAlpha){
        this.alpha = newAlpha;
    }

    getAlpha(){
        return this.alpha;
    }

    setForegroundColor(newColor){
        this.foregroundColor = newColor;
	    this.labelColor = newColor;
    }

    getHighlight(){
        return this.highlighted;
    }

    setHighlight(value){
        this.highlighted = value;
    }

    getWidth(){
        // TODO:  Do we want to throw here?  Should always override this ...
	    return 0;
    }

    getHeight(){
        // TODO:  Do we want to throw here?  Should always override this ...
	    return 0;
    }

    centerX(){
        return this.x;
    }

    setWidth(newWidth){
        // TODO:  Do we want to throw here?  Should always override this ... 
    }

    centerY(){
        return this.y;
    }

    getAlignLeftPos(otherObject){
        return [otherObject.right()+ this.getWidth() / 2, otherObject.centerY()];
    }

    getAlignRightPos(otherObject){
        return [otherObject.left() - this.getWidth() / 2, otherObject.centerY()];
    }

    getAlignTopPos(otherObject){
        return [otherObject.centerX(), otherObject.top() - this.getHeight() / 2];
    }

    getAlignBottomPos(otherObject){
        return [otherObject.centerX(), otherObject.bottom() + this.getHeight() / 2];
    }


    alignLeft(otherObject)
    {
        // Assuming centering.  Overridden method could modify if not centered
        //  (See AnimatedLabel, for instance)
        this.y = otherObject.centerY();
        this.x = otherObject.right() + this.getWidth() / 2;	
    }
    
    alignRight(otherObject)
    {
        // Assuming centering.  Overridden method could modify if not centered
        //  (See AnimatedLabel, for instance)
        this.y = otherObject.centerY();
        this.x = otherObject.left() - this.getWidth() / 2;	
    }
    
    
    alignTop(otherObject)
    {
        // Assuming centering.  Overridden method could modify if not centered
        
        this.x = otherObject.centerX();
        this.y = otherObject.top() - this.getHeight() / 2;	
        
        
    }
    
    
    alignBottom(otherObject)
    {
        this.x = otherObject.centerX();
        this.y = otherObject.bottom() + this.getHeight() / 2;		
        
    }
    
    
    
    /* TODO:  Do we need these in the base? 		
            function left(): Number
            {
                return x - getWidth() / 2;
            }
            
            function right():Number
            {
                return x + getWidth() / 2;
            }
            
            function top():Number
            {
                return y - getHeight() / 2;
            }
            
            function bottom():Number
            {
                return y + getHeight() / 2;
            }
            
            function centerX():Number
            {
                return x;
            }
            
            function centerY():Number
            {
                return y;
            }
            */
            
            
    getClosestCardinalPoint(fromX, fromY)
    {
        var xDelta;
        var yDelta;
        var xPos;
        var yPos;
                
        if (fromX < this.left())
        {
            xDelta = this.left() - fromX;
            xPos = this.left();
         }
        else if (fromX > this.right())
        {
            xDelta = fromX - this.right();
            xPos = this.right();
        }
        else
        {
            xDelta = 0;
            xPos = this.centerX();
        }
        
        if (fromY < this.top())
        {
            yDelta = this.top() - fromY;
            yPos = this.top();
        }
        else if (fromY > this.bottom())
        {
            yDelta = fromY - this.bottom();
            yPos = this.bottom();
        }
        else
        {
            yDelta = 0;
            yPos = this.centerY();
        }
                
        if (yDelta > xDelta)
        {
            xPos = this.centerX();
        }
        else 
        {
            yPos  = this.centerY();
        }
        
        return [xPos, yPos];
    }
            
            
    centered()
    {
        return false;
    }
    
    
    pulseHighlight(frameNum)
    {			
        if (this.highlighted)
        {
                    var frameMod = frameNum / 7.0;
                    var delta  = Math.abs((frameMod) % (2 * this.range  - 2) - this.range + 1)
                    this.highlightDiff =  delta + this.minHeightDiff;
        }
                
    }
            
    getTailPointerAttachPos(fromX, fromY, anchorPoint) 
    {
        return [this.x, this.y];
    }
            
            
    getHeadPointerAttachPos(fromX, fromY) 
    {
        return [this.x, this.y];
    }
            
    /*public function createUndoDelete() : UndoBlock
    {
                // Must be overriden!
                return null;
    }
    */		
    identifier()
    {
        return this.objectID;
    }
    
    getText(index)
    {
        return this.label;
    }
            
    getTextColor(textIndex)
    {			
        return this.labelColor
    }
            
    setTextColor(color, textIndex)
    {
            this.labelColor = color;
    }
            
    setText(newText, textIndex)
    {
        this.label = newText;
    }
    
    setHighlightIndex(hlIndex)
    {
       this.highlightIndex = hlIndex;
       this.highlightIndexDirty = true;
    }
    
    
    getHighlightIndex()
    {
       return this.highlightIndex;
    }


}